<template>
   <view>
      <view class="m-list" v-for="(item, index) in courseList" :key="index">
         <uni-list class="m-item">
            <uni-list-item>
               <view>
                 <span>{{item.name}}</span>
                 <button size="mini" @click="toBook(item)">预约</button>
                 <button size="mini" @click="toBookDetail(item)">已约</button>
               </view>
               <view>
                 {{item.teacherName}}
               </view>
               <view>
                 {{item.startTime}} - {{item.endTime}}
               </view>
            </uni-list-item>
         </uni-list>
      </view>
   </view>
</template>

<script>
   import env from '@/env';
   
   export default {
      data() {
         return {
            courseList: [] 
         }
      },
      onLoad(options) {
         console.log('token-->' + uni.getStorageSync('TOKEN'));
      	this.getCourseList();
      },
      methods: {
         getCourseList() {
            uni.request({
               url: env.BASE_URI +  '/course', //仅为示例，并非真实接口地址。
               success: (res) => {
                  this.courseList = res.data;
                  console.log(res.data);
               }
            });
         },
         toBook(course) {
            console.log('222---' + uni.getStorageSync('TOKEN'));
         },
         toBookDetail(course) {
            console.log(111);
            
            uni.navigateTo({
            	url: '/pages/book/preBook?courseId=' + course.id,
            });
         }
      }
   }
</script>

<style lang="scss" scoped>
	@import "./courses.scss";
</style>
